//base
import Taro, { Component } from '@tarojs/taro'
import { View, Text } from '@tarojs/components'
//less
import './index.less'
import tool from '../../../util/tool'

class BtnFixedDelete extends Component {
  constructor(props) {
    super(props)
    this.state = { canTab: true }
  }
  componentWillMount() {
    //onLoad
  }

  componentDidMount() {
    //onready
  }

  componentWillUnmount() {
    //onUnload
  }

  componentWillReceiveProps(nextprops) {}

  delay(time = 0) {
    return new Promise(resolve => {
      setTimeout(() => {
        resolve()
      }, time)
    })
  }
  taptimer = null
  onTap = tool.throttle(() => {
    if (this.props.cant) {
      return
    }
    if (this.state.canTab) {
      this.setState({
        canTab: false
      })
      this.props.onTap()
      this.taptimer = setTimeout(() => {
        this.setState({
          canTab: true
        })
        clearTimeout(this.taptimer)
      }, 1500)
    }
  })

  onDelete = tool.throttle(() => {
    // 删除操作
    this.props.onDelete()
  })

  render() {
    const { cant, leftText, rightText } = this.props
    return (
      <View className={`BtnFixedDelete_id06415 ${leftText ? 'two-btn' : ''}`}>
        <View className={`btn-left ${leftText ? '' : 'disNone'}`} onClick={this.onDelete}>
          {leftText}
        </View>
        <View
          className={`btn-right ${cant ? 'opacity_id123' : ''} ${leftText ? '' : 'one-btn'}`}
          onClick={this.onTap}
          cant={cant}
        >
          {rightText}
        </View>
      </View>
    )
  }
}

export default BtnFixedDelete
